<template>
  <div id="base-info-wrap" v-loading="loading">
    <el-descriptions :column="1" size="small" border colon>
      <el-descriptions-item label="唯一标识：">{{modelDefinition.id}}</el-descriptions-item>
      <el-descriptions-item label="模型名称：">{{modelDefinition.name}}</el-descriptions-item>
      <el-descriptions-item label="模型ID：">{{modelDefinition.code}}</el-descriptions-item>
      <el-descriptions-item label="标签编号：">{{modelDefinition.labelCode}}</el-descriptions-item>
      <el-descriptions-item label="图标类型：">{{modelDefinition.iconType}}</el-descriptions-item>
      <el-descriptions-item label="图标：">
        <div v-if="modelDefinition.icon && modelDefinition.iconType === 'element-ui'"><i :class="modelDefinition.icon"></i></div>
      </el-descriptions-item>
      <el-descriptions-item label="排序号：">{{modelDefinition.weight}}</el-descriptions-item>
      <el-descriptions-item label="描述：">{{modelDefinition.description}}</el-descriptions-item>
      <el-descriptions-item label="是否可实例化：">{{$booleanConvert(modelDefinition.instance)}}</el-descriptions-item>
      <el-descriptions-item label="是否已发布：">{{$booleanConvert(modelDefinition.published)}}</el-descriptions-item>
      <el-descriptions-item label="模型类型名称：">{{modelDefinition.className}}</el-descriptions-item>
      <el-descriptions-item label="表名称：">{{modelDefinition.tableName}}</el-descriptions-item>
      <el-descriptions-item label="是否可添加扩展属性：">{{$booleanConvert(modelDefinition.canAddExtAttr)}}</el-descriptions-item>
    </el-descriptions>
  </div>
</template>

<script>
import {getModelDefinition} from '@/js/api/model/modelDefinition'

export default {
  name: 'ModelDefinitionInfo',
  props: {
    id: {
      type: [String, Number],
      default: ''
    }
  },
  data(){
    return {
      modelDefinition: {},
      loading: true
    }
  },
  methods: {
    async getModelDefinition(id){
      this.loading = true
      const modelDefinition = await getModelDefinition(id || this.id)
      if (modelDefinition.errorMsg){
        this.$tips(modelDefinition.errorMsg, 'error')
        // this.$router.back()
      } else {
        this.modelDefinition = modelDefinition.data
      }
      this.loading = false
    }
  },
  created(){
    this.getModelDefinition()
  }
}
</script>

<style lang="less">
#base-info-wrap{
  height: inherit;
  overflow: auto;
  .el-descriptions{
    .el-descriptions-row{
      th{
        width: 200px;
        font-weight: 700;
        font-size: 14px;
        text-align: right;
      }
    }
  }
}
</style>
